package com.bigpang.framework.tomcat.ex02;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author YongQiang
 * @Date 2021/4/16 8:52
 * @Version 1.0
 */
public class PrimitiveServlet implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("init");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        System.out.println("service");
        ServletInputStream inputStream = req.getInputStream();
        PrintWriter out = res.getWriter();
        String outString = "<pre>Hello. Roses are red.</pre>";
        String responseStr =
                "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "Content-Length: " + outString.getBytes().length + "\r\n" +
                        "\r\n" + outString;
        out.println(responseStr);
        out.print("Violets are blue.");

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
